<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :md="6" :sm="12">
            <a-form-item :label=" $t('radio.fileName') ">
              <j-input :placeholder="$t('base.inputVagueQuery')" v-model="queryParam.fileName"></j-input>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search"> {{$t('base.query')}} </a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px"> {{$t('base.reset')}} </a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus"> {{$t('radio.uploadResources')}} </a-button>

      <a-button type="primary" @click="batchDel" icon="delete"> {{$t('base.del')}} </a-button>

    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> {{$t('base.selected')}} <a style="font-weight: 600">{{ selectedRowKeys.length }}</a> {{$t('base.item')}}
        <a style="margin-left: 24px" @click="onClearSelected"> {{$t('base.clear')}} </a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{fixed:true,selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;"> {{$t('radio.noSuchPicture')}} </span>
          <img v-else :src="getImgView(text)" height="25px" :alt=" $t('radio.pictureDoesNotExist') " style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;"> {{$t('radio.noSuchFile')}} </span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            {{$t('base.download')}}
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">

          <a-popconfirm :title=" $t('radio.doYouWantToDeleteIt') " @confirm="() => handleDelete(record.id)">
              <a> {{$t('base.del')}} </a>
          </a-popconfirm>
          <a-divider type="vertical"/>
          <a @click="resourceListening(record)"><a-icon type="notification" />  {{$t('radio.audition')}} </a>
          <a-divider type="vertical"/>
          <a href="javascript:;" @click="uploadResourceFile(record.filePath)"> {{$t('radio.download')}} </a>
        </span>

      </a-table>
    </div>

    <glrResource-modal ref="modalForm" @ok="modalFormOk"></glrResource-modal>
    <glr-resource-listening ref="resourceListening"></glr-resource-listening>
  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import GlrResourceModal from './modules/GlrResourceModal'
  import { validateDuplicateValue,filterObj } from '@/utils/util'
  import GlrResourceListening from "./modules/GlrResourceListening";
  import JInput from '@/components/jeecg/JInput'

  export default {
    name: "GlrResourceList",
    mixins:[JeecgListMixin],
    components: {
      GlrResourceListening,
      GlrResourceModal,
      JInput

    },
    data () {
      return {
        disableMixinCreated:true,
        description: '资源表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:this.$t('radio.fileName') ,
            align:"center",
            dataIndex: 'fileName'
          },
          {
            title: this.$t('radio.fileType') ,
            align:"center",
            dataIndex: 'fileType'
          },
          {
            title: this.$t('radio.fileSizeMb') ,
            align:"center",
            dataIndex: 'fileSize',
            customRender:function (text) {
              return (text/1024/1024).toFixed(2)+'(MB)'
            }
          },
          {
            title: this.$t('radio.playDuration')  ,
            align:"center",
            dataIndex: 'filePlayTime'
          },
          {
            title: this.$t('radio.radioManufacturer')  ,
            align:"center",
            dataIndex: 'companyCode_dictText'
          },
          {
            title: this.$t('radio.uploadTime')  ,
            align:"center",
            dataIndex: 'createTime',
            customRender:function (text) {
              return !text?"":(text.length>19?text.substr(0,19):text)
            }
          },
          {
            title: this.$t('base.operation'),
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/glr/glrResource/list",
          delete: "/glr/glrResource/delete",
          deleteBatch: "/glr/glrResource/deleteBatch",
          exportXlsUrl: "/glr/glrResource/exportXls",
          importExcelUrl: "glr/glrResource/importExcel",
        },
        dictOptions:{
        },
      }
    },
    created(){
      this.queryParam.equipmentType = 1;
      this.loadData();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      initDictConfig(){
      },
      resourceListening(record){
        this.$refs.resourceListening.edit(record);
        this.$refs.resourceListening.title = this.$t('radio.audition');
      },
      /* 文件下载 */
      uploadResourceFile(text){
        if(!text){
          this.$message.warning(this.$t('radio.unknownFile'))
          return;
        }
        if(text.indexOf(",")>0){
          text = text.substring(0,text.indexOf(","))
        }
        window.open(window._CONFIG['domianURL'] + "/glr/glrResource/download/"+text);
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>